#ifndef _Q_PIDDEVICE_H
#define _Q_PIDDEVICE_H

#include "stdint.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define Q_VAL_1_0F (0x8000L)	  
#define Q_VAL_0_5F (0x4000L)	  
#define Q_VAL_0_25F (0x2000L)	  
#define Q_VAL_0_125F (0x1000L)	  
#define Q_VAL_NV1_0F (-0x8000L)	  
#define Q_VAL_NV0_5F (-0x4000L)	  
#define Q_VAL_NV0_25F (-0x2000L)  
#define Q_VAL_NV0_125F (-0x1000L) 

	typedef struct
	{
		uint8_t p_dis_en;    
		uint8_t d_limit_p;	 
		uint8_t i_coef_en;	 
							 
		uint16_t kt;		 
		uint16_t kt_cycle;	 
		uint16_t kt_cnt;	 
							 
		int32_t q_sv;		 
		int32_t q_pv;		 
		int32_t q_dead_zone; 
		int32_t q_ki_coef;	 
							 
		int32_t q_p;		 
		int16_t i;			 
		int16_t d;			 
		int32_t p_old;		 
		int16_t i_old;
		int16_t d_old;
		uint16_t t_old;
		
		int32_t q_kp;	   
		int32_t q_ki;	   
		int32_t q_kd;	   
		int32_t q_dft;	   
		int32_t q_dv;	   
						   
		int32_t q_ival;	   
		int32_t q_pv_old;  
		int32_t q_err_old; 
		int32_t q_sv_old;  
						   
		int32_t q_imax;	   
		int32_t q_max;	   
		int32_t q_min;	   
						   
		int32_t q_out_flt; 
		int32_t q_out_fac; 
		int32_t q_out;	   
		uint8_t po_dis_st; 
		int16_t out;	   
	} q_pid_type;

	int32_t q_pid_update(q_pid_type *pid);
	int32_t q_pid_cal(q_pid_type *pid);
	void q_pid_clr(q_pid_type *pid);
	void q_pid_dv_clr(q_pid_type *pid);

	int32_t q12_pid_update(q_pid_type *pid);
	int32_t q12_pid_cal(q_pid_type *pid);
	void q12_pid_clr(q_pid_type *pid);
	void q12_pid_dv_clr(q_pid_type *pid);

#ifdef __cplusplus
}
#endif

#endif 
